home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10032 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: goto
  5. Date: 14 Mar 1996 19:55:02 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4i9tim$see@news.xs4all.nl>
  8. References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. Bill Simpson <wsimpson@uwinnipeg.ca> writes:
  13.  
  14. >There was a goto thread lately, and my problem is to state this algorithm 
  15. >cleanly without gotos (which I think is easy, but my attempts have been 
  16. >failures).
  17.  
  18. >0. x=0;
  19. >1. x+=erand(maxmean);
  20. >2. if (urand2()>rate(x)/maxrate)
  21. >    goto step 1
  22. >3. if (x<=XMAX)
  23. >    {
  24. >    setdot(x,y,z);
  25. >    goto step 1
  26. >    }
  27.  
  28. One possibility:
  29.  
  30. for(x=0;;)
  31. {   x+=erand(maxmean);
  32.     if(urand2()>rate(x)/maxrate)
  33.        continue;
  34.     if(x>XMAX)
  35.        break;
  36.  
  37.     setdot(x,y,z);
  38. }
  39.  
  40. Frank
  41. --
  42. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  43. ------------------------------------------------------------------------
  44. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  45.